package com.newpage.module_gather.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.recyclerview.widget.RecyclerView;

import com.newpage.module_gather.R;
import com.newpage.module_gather.treelist.Node;
import com.newpage.module_gather.treelist.TreeRecyclerAdapter;

import java.util.List;

public class SimpleTreeRecyclerAdapter extends TreeRecyclerAdapter {

    public SimpleTreeRecyclerAdapter(RecyclerView mTree, Context context, List<Node> datas, int defaultExpandLevel, int iconExpand, int iconNoExpand) {
        super(mTree, context, datas, defaultExpandLevel, iconExpand, iconNoExpand);
    }

    public SimpleTreeRecyclerAdapter(RecyclerView mTree, Context context, List<Node> datas, int defaultExpandLevel) {
        super(mTree, context, datas, defaultExpandLevel);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHoder(View.inflate(mContext, R.layout.gather_knowledge_item_pop,null));
    }

    @Override
    public void onBindViewHolder(final Node node, RecyclerView.ViewHolder holder, int position) {

        final MyHoder viewHolder = (MyHoder) holder;
        //todo do something

        if (node.getIcon() == -1) {
            viewHolder.icon.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.icon.setVisibility(View.VISIBLE);
            viewHolder.icon.setImageResource(node.getIcon());
        }

        if (node.isChecked()){
            viewHolder.label.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
//            viewHolder.label.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            if (node.getIcon() == R.drawable.ic_collapse){
                viewHolder.icon.setImageResource(R.drawable.ic_collapse_selected);
            }else if (node.getIcon() == R.drawable.ic_expand_normal){
                viewHolder.icon.setImageResource(R.drawable.ic_expand_selected);
            }
        }else if (node.isRoot()){
            viewHolder.label.setTextColor(mContext.getResources().getColor(R.color.black));
//            viewHolder.label.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }else {
            viewHolder.label.setTextColor(mContext.getResources().getColor(R.color.class_666666));
//            viewHolder.label.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }

        viewHolder.label.setText(node.getName());

    }


    class MyHoder extends RecyclerView.ViewHolder{


        public TextView label;

        public ImageView icon;
        public MyHoder(View itemView) {
            super(itemView);

            label = itemView.findViewById(R.id.tv_examination_point);
            icon =  itemView.findViewById(R.id.iv_examination_point_arrow);

        }

    }
}
